Ext.define("PCD.controller.CarController",{
	extend: "Ext.app.Controller",

	views: [
		"car.CarList",
		"car.CarEdit"
	],

	stores: [
		"CarStore"
	],

	models: [
		"CarModel"
	],

	carview:null,

	pcdview:null,

	init:function(){
		console.log("CarController init");
		this.control({
            "carlist dataview": {
                itemdblclick: this.editCar
            },
            "caredit button[action=apply]":{
            	click: this.applyCar
            }
        });
	},

	editCar:function(grid, record){
		if(!this.carview){
			this.carview = Ext.create("PCD.view.car.CarEdit");
		}
		this.carview.show();

		this.carview.down("form").loadRecord(record);

		if(record.get("zt") === "0"){
			this.carview.down("button").disable();
		}else{
			this.carview.down("button").enable();
		}
	},
	applyCar:function(){
		if(!this.pcdview){
			this.pcdview = Ext.create("PCD.view.pcd.PcdEdit");
		}
		this.pcdview.show();
	}
});